package com.java.demos.web.Controller;

import com.java.demos.web.Pojo.Address;
import com.java.demos.web.Pojo.Result;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/*
    测试响应数据
 */
@RestController
// @RestController = @Controller +  @ResponseBody
public class ResponseController {
//    @RequestMapping("/helloStr")
//    public String helloStr(){
//        System.out.println("hello world~");
//        return "hello world~";
//    }
//
//    @RequestMapping("/getAddr")
//    public Address getAddr(){
//        Address address = new Address();
//        address.setCity("北京");
//        address.setProvince("广东");
//        return address;
//    }
//
//    @RequestMapping("/listAddr")
//    public List<Address> listAddr(){
//        List<Address> list = new ArrayList<>();
//        Address address1 = new Address();
//        address1.setCity("北京");
//        address1.setProvince("广东");
//        list.add(address1);
//
//        Address address2 = new Address();
//        address2.setCity("上海");
//        address2.setProvince("广西");
//        list.add(address2);
//
//        return list;
//    }

    //利用result封装类返回response数据
    @RequestMapping("/helloStr")
    public Result helloStr(){
        System.out.println("hello world~");
        return Result.success();
    }

    @RequestMapping("/getAddr")
    public Result getAddr(){
        Address address = new Address();
        address.setCity("北京");
        address.setProvince("广东");
        return Result.success(address);
    }

    @RequestMapping("/listAddr")
    public Result listAddr(){
        List<Address> list = new ArrayList<>();
        Address address1 = new Address();
        address1.setCity("北京");
        address1.setProvince("广东");
        list.add(address1);

        Address address2 = new Address();
        address2.setCity("上海");
        address2.setProvince("广西");
        list.add(address2);

        return Result.success(list);
    }
}
